#ifndef HSE_STRUCTURED_INDEX_H
#define HSE_STRUCTURED_INDEX_H

#include <string>
#include <vector>
#include <algorithm>
#include "hse_common.h"
#include "hse_types.h"

namespace hse {
using std::string;
using std::vector;
using std::map;

//10MB buffer size
#define INDEX_FILE_BUFFER_SIZE 1024 * 1024 * 50

/**
 IndexFileStructure:
 2 byte: headerlength
   |header->    4 byte:wordcount  4 byte:position offset position 1 byte:startwordlength  startword  
   |vocabulary  1 byte:word1len  word1  1 byte:word2len  word2 ...
   |position offset  4 byte:word1position 4 byte:word2position ...
   |position    4 byte:docid 4 byte:count 4 byte:p1 4byte:p2 ...  4 byte:docid 
 */
class StructuredIndex {
public:
	explicit StructuredIndex(std::map<string, Posting*, StringLess>& postings);
	int Dump(FILE *f);
	int Load(FILE *f);
private:
	/*unsigned short	header_length_;
	unsigned char	start_word_length_;
	const char		*start_word_;
	unsigned short	wordcount_;
	unsigned short	position_offset_;*/

	std::map<string, Posting*, StringLess>& postings_;

	DISALLOW_COPY_AND_ASSIGN(StructuredIndex);
};

} //end of namespace

#endif